package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.mapper.LhkHotelReviewMapper;
import com.ruoyi.system.mapper.LhkOrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.LhkHotelDetailsMapper;
import com.ruoyi.system.domain.LhkHotelDetails;
import com.ruoyi.system.service.ILhkHotelDetailsService;

/**
 * 实体详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-06
 */
@Service
public class LhkHotelDetailsServiceImpl implements ILhkHotelDetailsService 
{
    @Autowired
    private LhkHotelDetailsMapper lhkHotelDetailsMapper;

    @Autowired
    private LhkHotelReviewMapper lhkHotelReviewMapper;

    @Autowired
    private LhkOrdersMapper lhkOrdersMapper;

    /**
     * 查询实体详情
     * 
     * @param detailId 实体详情主键
     * @return 实体详情
     */
    @Override
    public LhkHotelDetails selectLhkHotelDetailsByDetailId(Long detailId)
    {
        return lhkHotelDetailsMapper.selectLhkHotelDetailsByDetailId(detailId);
    }

    /**
     * 查询实体详情列表
     * 
     * @param lhkHotelDetails 实体详情
     * @return 实体详情
     */
    @Override
    public List<LhkHotelDetails> selectLhkHotelDetailsList(LhkHotelDetails lhkHotelDetails)
    {
        List<LhkHotelDetails> lhkHotelDetails1 = lhkHotelDetailsMapper.selectLhkHotelDetailsList(lhkHotelDetails);
        LhkHotelDetails lhkHotelDetails3 = new LhkHotelDetails();
        for (LhkHotelDetails lhkHotelDetails2 : lhkHotelDetails1) {
            System.out.println("----------------------55行");
            System.out.println(lhkHotelDetails2);
            // 获取酒店的收益
            lhkHotelDetails2.setHotelShouyi(getShouyi(lhkHotelDetails2));
            // 获取酒店的退款人数
            lhkHotelDetails2.setTuikuangrenshu(getTuikuangrenshu(lhkHotelDetails2));
            // 获取酒店的评价人数
            lhkHotelDetails2.setPingjiashu(Long.valueOf(getPingJiaShu(lhkHotelDetails2)));
            // 获取酒店的评价星级
            lhkHotelDetails2.setPingjiaxingji(getPingjiaxingji(lhkHotelDetails2));
            // 获取消费人数
            lhkHotelDetails2.setXiaofeirenshu(getXiaofeirenshu(lhkHotelDetails2));
            lhkHotelDetails3.setDetailId(lhkHotelDetails2.getDetailId());
            lhkHotelDetails3.setPingjiashu(lhkHotelDetails2.getPingjiashu());
            lhkHotelDetails3.setPingjiaxingji(lhkHotelDetails2.getPingjiaxingji());
            lhkHotelDetails3.setHotelShouyi(lhkHotelDetails2.getHotelShouyi());
            lhkHotelDetailsMapper.updateLhkHotelDetails(lhkHotelDetails3);
            System.out.println("-----------------69行");
            System.out.println(lhkHotelDetails2);
        }
        return lhkHotelDetails1;
    }

    /**
     * 新增实体详情
     * 
     * @param lhkHotelDetails 实体详情
     * @return 结果
     */
    @Override
    public int insertLhkHotelDetails(LhkHotelDetails lhkHotelDetails)
    {
        return lhkHotelDetailsMapper.insertLhkHotelDetails(lhkHotelDetails);
    }

    /**
     * 修改实体详情
     * 
     * @param lhkHotelDetails 实体详情
     * @return 结果
     */
    @Override
    public int updateLhkHotelDetails(LhkHotelDetails lhkHotelDetails)
    {
        return lhkHotelDetailsMapper.updateLhkHotelDetails(lhkHotelDetails);
    }

    /**
     * 批量删除实体详情
     * 
     * @param detailIds 需要删除的实体详情主键
     * @return 结果
     */
    @Override
    public int deleteLhkHotelDetailsByDetailIds(Long[] detailIds)
    {
        return lhkHotelDetailsMapper.deleteLhkHotelDetailsByDetailIds(detailIds);
    }

    /**
     * 删除实体详情信息
     * 
     * @param detailId 实体详情主键
     * @return 结果
     */
    @Override
    public int deleteLhkHotelDetailsByDetailId(Long detailId)
    {
        return lhkHotelDetailsMapper.deleteLhkHotelDetailsByDetailId(detailId);
    }
    // 获取酒店的收益
    public Long getShouyi(LhkHotelDetails lhkHotelDetails) {
        Long hotelShouyi = 0L;
        if (lhkHotelDetails != null) {
            Long hotelIncomeByHotelId = (lhkOrdersMapper.getHotelIncomeByHotelId(lhkHotelDetails.getHotelId()));
            System.out.println("酒店收益：" + hotelIncomeByHotelId);
            if (hotelIncomeByHotelId!= null) {
                hotelShouyi = hotelIncomeByHotelId;
            }
        }
        return hotelShouyi;
    }

    // 获取酒店的退款人数
    public Long getTuikuangrenshu(LhkHotelDetails lhkHotelDetails) {
        Integer i = 0;
        if (lhkHotelDetails!= null) {
            Integer refundCountByHotelId = lhkOrdersMapper.getRefundCountByHotelId(lhkHotelDetails.getHotelId());
            if (refundCountByHotelId!= null) {
                i = refundCountByHotelId;
            }
        }
        return i.longValue();
    }
    // 获取酒店的评价人数
    public Long getPingJiaShu(LhkHotelDetails lhkHotelDetails) {
        Integer reviewCount = 0;
        if (lhkHotelDetails!= null) {
            reviewCount = lhkHotelReviewMapper.getReviewCountByHotelId(lhkHotelDetails.getHotelId());
            if (reviewCount == null) {
                reviewCount = 0;
            }
        }
        return Long.valueOf(reviewCount);
    }

    // 获取酒店的评价星级
    public Double getPingjiaxingji(LhkHotelDetails lhkHotelDetails) {
        Double avgScore = 0.0;
        if (lhkHotelDetails!= null) {
            Double avgScoreByHotelId = lhkHotelReviewMapper.getAvgScoreByHotelId(lhkHotelDetails.getHotelId());
            if (avgScoreByHotelId != null) {
                return Math.round(avgScoreByHotelId * 10.0) / 10.0;
            }
        }
        return avgScore;
    }

    // 获取酒店的消费人数
    public Long getXiaofeirenshu(LhkHotelDetails lhkHotelDetails) {
        Integer i = 0;
        if (lhkHotelDetails!= null) {
            Integer orderCountByHotelId = lhkOrdersMapper.getOrderCountByHotelId(lhkHotelDetails.getHotelId());
            if (orderCountByHotelId!= null) {
                i = orderCountByHotelId;
            }

        }
        return i.longValue();
    }

}
